<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
<html><head><title>QReadLocker Class Reference</title><style>h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm }
a:link { color: #004faf; text-decoration: none }
a:visited { color: #672967; text-decoration: none }
td.postheader { font-family: sans-serif }
tr.address { font-family: sans-serif }
body { background: #ffffff; color: black; }
</style></head><body><table border="0" cellpadding="0" cellspacing="0" width="100%"><tr /><td align="left" valign="top" width="32"><img align="left" border="0" height="32" src="images/rb-logo.png" width="32" /></td><td width="1">&#160;&#160;</td><td class="postheader" valign="center"><a href="../pyqt4ref.html"><font color="#004faf">Home</font></a>&#160;&#183; <a href="classes.html"><font color="#004faf">All Classes</font></a>&#160;&#183; <a href="modules.html"><font color="#004faf">Modules</font></a></td></table><h1 align="center">QReadLocker Class Reference<br /><sup><sup>[<a href="qtcore.html">QtCore</a> module]</sup></sup></h1><p>The QReadLocker class is a convenience class that simplifies locking and unlocking read-write locks for read access. <a href="#details">More...</a></p>
<h3>Methods</h3><ul><li><div class="fn" /><b><a href="qreadlocker.html#QReadLocker">__init__</a></b> (<i>self</i>, QReadWriteLock)</li><li><div class="fn" />QReadWriteLock <b><a href="qreadlocker.html#readWriteLock">readWriteLock</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qreadlocker.html#relock">relock</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qreadlocker.html#unlock">unlock</a></b> (<i>self</i>)</li></ul><h3>Special Methods</h3><ul><li><div class="fn" />object <b><a href="qreadlocker.html#__enter__">__enter__</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qreadlocker.html#__exit__">__exit__</a></b> (<i>self</i>, object&#160;<i>type</i>, object&#160;<i>value</i>, object&#160;<i>traceback</i>)</li></ul><a name="details" /><hr /><h2>Detailed Description</h2><p>The QReadLocker class is a convenience class that simplifies locking and unlocking read-write locks for read access.</p>
<p>The purpose of QReadLocker (and <a href="qwritelocker.html">QWriteLocker</a>) is to simplify <a href="qreadwritelock.html">QReadWriteLock</a> locking and unlocking. Locking and unlocking statements or in exception handling code is error-prone and difficult to debug. QReadLocker can be used in such situations to ensure that the state of the lock is always well-defined.</p>
<p>Here's an example that uses QReadLocker to lock and unlock a read-write lock for reading:</p>
<pre> QReadWriteLock lock;

 QByteArray readData()
 {
     QReadLocker locker(&amp;lock);
     ...
     return data;
 }</pre>
<p>It is equivalent to the following code:</p>
<pre> QReadWriteLock lock;

 QByteArray readData()
 {
     lock.lockForRead();
     ...
     lock.unlock();
     return data;
 }</pre>
<p>The <a href="qmutexlocker.html">QMutexLocker</a> documentation shows examples where the use of a locker object greatly simplifies programming.</p>
<p>See also <a href="qwritelocker.html">QWriteLocker</a> and <a href="qreadwritelock.html">QReadWriteLock</a>.</p>
<hr /><h2>Method Documentation</h2><h3 class="fn"><a name="QReadLocker" />QReadLocker.__init__ (<i>self</i>, <a href="qreadwritelock.html">QReadWriteLock</a>)</h3><p>Constructs a <a href="qreadlocker.html">QReadLocker</a> and locks <i>lock</i> for reading. The lock will be unlocked when the <a href="qreadlocker.html">QReadLocker</a> is destroyed. If <tt>lock</tt> is zero, <a href="qreadlocker.html">QReadLocker</a> does nothing.</p>
<p>See also <a href="qreadwritelock.html#lockForRead">QReadWriteLock.lockForRead</a>().</p>
<a name="//apple_ref/cpp/instm/QReadLocker/~QReadLocker" />
<h3 class="fn"><a name="readWriteLock" /><a href="qreadwritelock.html">QReadWriteLock</a> QReadLocker.readWriteLock (<i>self</i>)</h3><p>Returns a pointer to the read-write lock that was passed to the constructor.</p>
<a name="//apple_ref/cpp/instm/QReadLocker/relock" />
<h3 class="fn"><a name="relock" />QReadLocker.relock (<i>self</i>)</h3><p>Relocks an unlocked lock.</p>
<p>See also <a href="qreadlocker.html#unlock">unlock</a>().</p>
<a name="//apple_ref/cpp/instm/QReadLocker/unlock" />
<h3 class="fn"><a name="unlock" />QReadLocker.unlock (<i>self</i>)</h3><p>Unlocks the lock associated with this locker.</p>
<p>See also <a href="qreadwritelock.html#unlock">QReadWriteLock.unlock</a>().</p>
<p /><h3 class="fn"><a name="__enter__" />object QReadLocker.__enter__ (<i>self</i>)</h3><h3 class="fn"><a name="__exit__" />QReadLocker.__exit__ (<i>self</i>, object&#160;<i>type</i>, object&#160;<i>value</i>, object&#160;<i>traceback</i>)</h3><address><hr /><div align="center"><table border="0" cellspacing="0" width="100%"><tr class="address"><td align="left" width="25%">PyQt&#160;snapshot-4.7.1-5014f7c72a58 for X11</td><td align="center" width="50%">Copyright &#169; <a href="http://www.riverbankcomputing.com">Riverbank&#160;Computing&#160;Ltd</a> and <a href="http://www.qtsoftware.com">Nokia</a> 2010</td><td align="right" width="25%">Qt&#160;4.6.1</td></tr></table></div></address></body></html>